﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using Mjollnir.Collections.Generic;
using System.Collections.Generic;

namespace Test.Mjollnir.Collections.Generic
{
    [TestClass]
    public class DictionaryExtensionsTest
    {
        static readonly Dictionary<int, string> dict = new Dictionary<int, string>
        {
            { 1, "One" }, { 2, "Two" }, { 3, "Three" }
        };

        [TestMethod]
        public void GetValueOrDefaultTest1()
        {
            {
                var expected = dict[2];
                var actual = dict.GetValueOrDefault(2);

                Assert.AreEqual(expected, actual);
            }

            {
                var expected = default(string);
                var actual = dict.GetValueOrDefault(9);

                Assert.AreEqual(expected, actual);
            }
        }

        [TestMethod]
        public void InvokeIfContainsKeyTest1()
        {
            {
                var expected = dict[2];
                var actual = default(string);

                dict.IfContainsKey(2, value => actual = value);

                Assert.AreEqual(expected, actual);
            }

            {
                var expected = dict[2];
                var actual = default(string);

                dict.IfContainsKey(2, value => actual = value);

                Assert.AreEqual(expected, actual);
            }
        }
    }
}
